package com.fjut.pms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fjut.pms.dao.IBaseDao;
import com.fjut.pms.pojo.Employee;
import com.fjut.pms.service.IEmployeeService;
import com.fjut.pms.utils.PageBean;

public class EmployeeServiceImpl implements IEmployeeService {

	private IBaseDao empDao;

	public PageBean findEmps(PageBean page, Object o) {
		String hql = "from Employee emp where 1=1 ";
		String countHql = "select count(*) from Employee emp where 1=1 ";
		return empDao.findPageByHql(page.getPageNo(), page.getPageSize(), hql,
				countHql, new HashMap());
	}

	public boolean checkEmp(Employee emp) {
		String hql = "from Employee emp where 1=1 and emp.no=:no and emp.password=:password";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("no", emp.getNo());
		map.put("password", emp.getPassword());
		Object o = empDao.findByHql(hql, map);
		if (null != o)
			return true;
		return false;
	}

	public IBaseDao getEmpDao() {
		return empDao;
	}

	public void setEmpDao(IBaseDao empDao) {
		this.empDao = empDao;
	}

	public Employee findByNo(String no) {
		String hql = "from Employee emp where 1=1 and emp.no=:no";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("no", no);
		return (Employee) empDao.findByHql(hql, map);
	}

	public List findDeparts() {
		String hql = "from Department depart";
		return empDao.findListByHql(hql);
	}

	public void save(Employee emp) {
		empDao.save(emp);
	}

	public void update(Employee employee) {
		empDao.saveOrUpdate(employee);
	}
}
